unit uActiveDesktop;

interface
Uses Windows,
     ComObj,
     ActiveX
     ;

Const _CLSID_ActiveDesktop = '{75048700-EF1F-11D0-9888-006097DEACF9}';
      IID_ActiveDesktop = '{F490EB00-1240-11D1-9888-006097DEACF9}';

      CLSID_ActiveDesktop : TGUID = _CLSID_ActiveDesktop;

Type TTagWallpaperOpt = packed Record
       dwSize : LongInt;
       dwStyle : Longint;
     End;

Type TTagComponentsOpt = packed Record
       dwSize : LongInt;
       fEnableComponents : Bool;
       fActiveDesktop : Bool;
     End;

Type TTagCompPos = packed Record
       dwSize : LongInt;             //Size of this structure
       iLeft : Integer;              //Left of top-left corner in screen co-ordinates.
       iTop : Integer;               //Top of top-left corner in screen co-ordinates.
       dwWidth : LongInt;            // Width in pixels.
       dwHeight : LongInt;           // Height in pixels.
       izIndex : Integer;            // Indicates the Z-order of the component.
       fCanResize : Bool;         // Is the component resizeable?
       fCanResizeX : Bool;        // Resizeable in X-direction?
       fCanResizeY : Bool;        // Resizeable in Y-direction?
       iPreferredLeftPercent : Integer;    //Left of top-left corner as percent of screen width
       iPreferredTopPercent : Integer;     //Top of top-left corner as percent of screen height
     End;

Type TTagComponent = packed Record
       dwSize : LongInt;             //Size of this structure
       dwID : LongInt;               //Reserved: Set it always to zero.
       iComponentType : Integer;     //One of COMP_TYPE_*
       fChecked : Bool;           // Is this component enabled?
       fDirty : Bool;             // Had the component been modified and not yet saved to disk?
       fNoScroll : Bool;          // Is the component scrollable?
       cpPos : TTagCompPos;              // Width, height etc.,
       {WCHAR   wszFriendlyName[MAX_PATH];          // Friendly name of component.
       WCHAR   wszSource[INTERNET_MAX_URL_LENGTH]; //URL of the component.
       WCHAR   wszSubscribedURL[INTERNET_MAX_URL_LENGTH]; //Subscrined URL }
    End;

Type IActiveDesktop = Interface( IUnknown )
       [IID_ActiveDesktop]
       Function ApplyChanges( Flags : LongInt ) : HResult; stdcall;
       Function GetWallpaper( pwszWallpaper : PChar; cchWallpaper : LongInt; dwReserved : LongInt) : HResult; stdcall;
       Function SetWallpaper( const pwszWallpaper : String; dwReserved : LongInt ): HResult; stdcall;
       Function GetWallpaperOptions(var Options : TTagWallpaperOpt; dwReserved : LongInt): HResult; stdcall;
       Function SetWallpaperOptions(const Options : TTagWallpaperOpt; dwReserved : LongInt): HResult; stdcall;
       Function GetPattern( pwszPattern : PChar; cchPattern : LongInt; dwReserved : LongInt ): HResult; stdcall;
       Function SetPattern( const pwszPattern : String; dwReserved : LongInt ): HResult; stdcall;
       Function GetDesktopItemOptions( var pco : TTagComponentsOpt; dwReserved : LongInt): HResult; stdcall;
       Function SetDesktopItemOptions( const pco : TTagComponentsOpt; dwReserved : LongInt): HResult; stdcall;
       Function AddDesktopItem(const pcomp : TTagComponent; dwReserved : LongInt): HResult; stdcall;
{       Function AddDesktopItemWithUI(HWND hwnd, LPCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;
       Function ModifyDesktopItem(LPCCOMPONENT pcomp, DWORD dwFlags): HResult; stdcall;
       Function RemoveDesktopItem(LPCCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;
       Function GetDesktopItemCount(LPINT lpiCount, DWORD dwReserved): HResult; stdcall;
       Function GetDesktopItem(int nComponent, LPCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;
       Function GetDesktopItemByID(DWORD dwID, LPCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;
       Function GenerateDesktopItemHtml(LPCWSTR pwszFileName, LPCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;
       Function AddUrl(HWND hwnd, LPCWSTR pszSource, LPCOMPONENT pcomp, DWORD dwFlags): HResult; stdcall;
       Function GetDesktopItemBySource(LPCWSTR pwszSource, LPCOMPONENT pcomp, DWORD dwReserved): HResult; stdcall;}
     End;

Function ActiveDesktopRunning : Boolean;

implementation

Function ActiveDesktopRunning;
Var ActiveDesktop : IActiveDesktop;
    Info : TTagComponentsOpt;
Begin
  Result := False;
  FillChar( Info, SizeOf( Info ), 0 );
  Info.dwSize := SizeOf( Info );
  try
    {CoGetClassInstance}
    OleCheck( CoCreateInstance(CLSID_ActiveDesktop, nil, CLSCTX_INPROC_SERVER, IActiveDesktop, ActiveDesktop ));
    OleCheck( ActiveDesktop.GetDesktopItemOptions( Info,0 ));
    Result := Info.fActiveDesktop;
  except
    ActiveDesktop := nil;
  end;
End;

end.
